package com.demo.starter.dao;

import com.demo.starter.model.User;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface StarterUserMapper {
    int deleteByPrimaryKey(Long id);

    int insert(User record);

    int insertSelective(User record);

    User selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(User record);

    int updateByPrimaryKey(User record);

    List<User> queryByUserIds(@Param("list") List<Long> userIds);

    @ResultMap("BaseResultMap")
    @Select("select id, user_id, user_name from user where user_id = #{userId}")
    List<User> queryByUserId(@Param("userId") Long userId);

    @MapKey("id")
    @ResultMap("BaseResultMap")
    @Select("select id, user_id, user_name from user")
    Map<Long, User> queryAllMapKey();

    /**
     * value值不能是List集合，只能是实体对象
     * @return
     */
    @MapKey("userName")
    @ResultMap("BaseResultMap")
    @Select("select id, user_id, user_name from user")
    Map<Long, List<User>> queryAllMapKeyGroupByUserName();

    @ResultMap("BaseResultMap")
    @Select("select id, user_id, user_name from user where user_id > #{userId}")
    List<User> queryByUserIdGt(@Param("userId") Long userId);

    @ResultMap("BaseResultMap")
    @Select("select id, user_id, user_name from user where user_id < #{userId}")
    List<User> queryByUserIdLt(@Param("userId") Long userId);

    @ResultMap("BaseResultMap")
    @Select("select id, user_id, user_name from user where user_id <= #{maxUserId} and user_id >= #{minUserId}")
    List<User> queryByUserIdBetween(@Param("minUserId") Long minUserId, @Param("maxUserId") Long maxUserId);

    @ResultMap("BaseResultMap")
    @Select("select id, user_id, user_name from user where user_name = #{userName} and user_id >= #{userId}")
    List<User> queryByUserNameIdGt(@Param("userName") String userName, @Param("userId") Long userId);
}